package com.my.hp_hr.contorller;

import com.my.hp_hr.entity.Department;
import com.my.hp_hr.service.DepartmentService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/departmentUpdateServlet")
public class DepartmentUpdateServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
            req.setCharacterEncoding("utf-8");
            String id = req.getParameter("id");
            String department_number = req.getParameter("department_number");
            String name = req.getParameter("name");
            String telephone = req.getParameter("telephone");
            String address = req.getParameter("address");
            String notes = req.getParameter("notes");
            Department department = new Department(Integer.parseInt(id),Integer.parseInt(department_number),name,null,telephone,address,notes);
            DepartmentService departmentService = new DepartmentService();
            departmentService.departmentUpdate(department);
            req.getRequestDispatcher("departmentListServlet").forward(req,resp);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
